﻿using System;
using System.Text;
using BusinessLogic.BusinessRules;
using BusinessLogic.ClassFactory;
using Common;
using DataCach;
using RichPlugins;

namespace IssueCommon
{
    public class ReplaceSPlugin
    {
        ///// <summary>
        ///// 处理多栏目文章列表插件
        ///// </summary>
        ///// <param name="objPlugin"></param>
        ///// <returns></returns>
        //public static string ReplaceMoreSectionArticleListPlugin(Plugin objPlugin, int _intDefaultID)
        //{
        //    // 文章所在栏目ID
        //    string strXml = string.Empty;
        //    string strSTID = objPlugin.GetValueByTagName("id");
        //    int intSTID = 0;
        //    if (strSTID == string.Empty)
        //    {
        //        if (_intDefaultID == -1)
        //        {
        //            string strMsg = string.Format("插件中无栏目ID!插件标识内容为{0}", objPlugin.Xml);
        //            throw new IssueCommon.CustomException(strMsg);
        //        }

        //        // 插件中未定义栏目ID,采用当前栏目ID
        //        intSTID = _intDefaultID;
        //    }
        //    else
        //    {
        //        intSTID = int.Parse(strSTID);
        //    }

        //    // 文章列表显示的数量
        //    int intTotalCount = -1;	// -1表示取出所有文章
        //    string strTotalCount = objPlugin.GetValueByTagName("TotalCount");
        //    if (strTotalCount != string.Empty)
        //    {
        //        intTotalCount = int.Parse(strTotalCount);
        //    }

        //    //strXml = GetCachXml(intSTID, Model.Common.Plugin.PluginType.ArticleList, intTotalCount);
        //    //// 有缓存的Xml,返回缓存数据
        //    //if (strXml != string.Empty)
        //    //{
        //    //    return strXml;
        //    //}

        //    using (SectionsFactory objFactory = new SectionsFactory())
        //    {
        //        Sections objSection = objFactory.Creator(intSTID);
        //        if (objSection == null)
        //        {
        //            string strMsg = string.Format("处理文章列表插件时未找到栏目，ID={0}", intSTID);
        //            throw new IssueCommon.CustomException(strMsg);
        //        }
        //        // 栏目停用，不发布
        //        if (objSection.DataItem.intState == (int)Common.Section.STState.Canceled)
        //        {
        //            strXml = string.Empty;	// 需要返回空字串,以替换模板中的相应内容
        //        }
        //        else if (objSection.DataItem.intDisplay == (int)Common.Section.STDisplay.No) // 栏目不显示，不发布
        //        {
        //            strXml = string.Empty;
        //        }
        //        else
        //        {
        //            strXml = objSection.GetSinglePageArticleXML(intTotalCount);

        //            //// 将Xml缓存
        //            //XmlCach objXmlCach = new XmlCach(intSTID, Model.Common.Plugin.PluginType.ArticleList, intTotalCount, strXml);
        //            //m_aryXmlCach.Add(objXmlCach);
        //        }
        //    }

        //    return strXml;
        //}

        /// <summary>
        /// 处理文章列表插件
        /// </summary>
        /// <param name="objPlugin"></param>
        /// <returns></returns>
        public static string ReplaceArticleListPlugin(Plugin objPlugin, int _intDefaultID, SessionUser sessionUser,bool bolFilterCurrentArticle,int intArtSecID)
        {
            // 文章所在栏目ID
            string strXml = string.Empty;
            string strSTID = objPlugin.GetValueByTagName("id");

            StringBuilder strSqlArticleStatue = new StringBuilder();
            bool bolIsGlobalStatus = false;
            bool bolFilterSame = false;
            bool bolFilterStatus = false;
            bool bolShowInIndex = false;
            bool bolDisabled = false;
            //全局
            string strGlobal = objPlugin.GetValueByTagName("global");
            //过滤状态项
            string strFilterStatus = objPlugin.GetValueByTagName("filterstatus");
            //置顶
            string strTop = objPlugin.GetValueByTagName("top");
            //推荐
            string strRec = objPlugin.GetValueByTagName("rec");
            //审核
            string strVerify = objPlugin.GetValueByTagName("verify");
            //滚动新闻
            string strScroll = objPlugin.GetValueByTagName("scroll");
            //包含子栏目列表
            string strContainChildSection = objPlugin.GetValueByTagName("ContainChildSection");
            //显示在首页
            string strShowInIndex = objPlugin.GetValueByTagName("ShowInIndex");
            //过滤重复
            string strContainFilterSame = objPlugin.GetValueByTagName("FilterSame");
            //是否禁用
            string strDisabled = objPlugin.GetValueByTagName("disabled");
            if (strDisabled != string.Empty)
            {
                if (strDisabled == "1")
                {
                    bolDisabled = true;
                }
            }
            if (bolDisabled == false)
            {
                if (strFilterStatus != string.Empty)
                {
                    if (strFilterStatus == "1")
                    {
                        bolFilterStatus = true;
                    }
                }
                if (strContainFilterSame != string.Empty)
                {
                    if (strContainFilterSame == "1")
                    {
                        bolFilterSame = true;
                    }
                }
                if (strShowInIndex != string.Empty)
                {
                    if (strShowInIndex == "1")
                    {
                        bolShowInIndex = true;
                    }
                }
                if (strTop != string.Empty)
                {
                    if (strTop == "1" && strGlobal == "1")
                    {
                        //全局置顶
                        strSqlArticleStatue.Append(string.Format(" and intGlobalTop ={0}", "1"));
                        bolIsGlobalStatus = true;
                    }
                    else if (strTop == "1")
                    {
                        if (bolFilterStatus)
                        {
                            //过滤板块置顶
                            strSqlArticleStatue.Append(string.Format(" and intSectionTop <>{0}", "1"));
                        }
                        else
                        {
                            //板块置顶
                            strSqlArticleStatue.Append(string.Format(" and intSectionTop ={0}", "1"));
                        }
                    }
                }
                else if (strRec != string.Empty)
                {
                    if (strRec == "1" && strGlobal == "1")
                    {
                        //全局推荐
                        strSqlArticleStatue.Append(string.Format(" and intGlobalRec ={0}", "1"));
                        bolIsGlobalStatus = true;
                    }
                    else if (strRec == "1")
                    {
                        if (bolFilterStatus)
                        {
                            //过滤板块推荐
                            strSqlArticleStatue.Append(string.Format(" and intSectionRec <>{0}", "1"));
                        }
                        else
                        {
                            //板块推荐
                            strSqlArticleStatue.Append(string.Format(" and intSectionRec ={0}", "1"));
                        }
                    }
                }
                else if (strVerify != string.Empty)
                {
                    if (strVerify == "1" && strGlobal == "1")
                    {
                        //全局审核
                        strSqlArticleStatue.Append(string.Format(" and intVerify ={0}", "1"));
                        bolIsGlobalStatus = true;
                    }
                    else if (strVerify == "1")
                    {
                        if (bolFilterStatus)
                        {
                            //过滤板块审核
                            strSqlArticleStatue.Append(string.Format(" and intVerify <>{0}", "1"));
                        }
                        else
                        {
                            //板块审核
                            strSqlArticleStatue.Append(string.Format(" and intVerify ={0}", "1"));
                        }
                    }
                }
                else if (strScroll != string.Empty)
                {
                    if (strScroll == "1" && strGlobal == "1")
                    {
                        //全局滚动
                        strSqlArticleStatue.Append(string.Format(" and intScroll ={0}", "1"));
                        bolIsGlobalStatus = true;
                    }
                    else if (strScroll == "1")
                    {
                        if (bolFilterStatus)
                        {
                            //过滤板块滚动
                            strSqlArticleStatue.Append(string.Format(" and intScroll <>{0}", "1"));
                        }
                        else
                        {
                            //板块滚动
                            strSqlArticleStatue.Append(string.Format(" and intScroll ={0}", "1"));
                        }
                    }
                }

                if (strSTID == string.Empty)
                {
                    if (_intDefaultID == -1)
                    {
                        if (bolIsGlobalStatus == false)
                        {
                            string strMsg = string.Format("插件中无栏目ID!插件标识内容为{0}", objPlugin.Xml);
                            throw new IssueCommon.CustomException(strMsg);
                        }
                        else
                        {
                            using (SectionsFactory objFactory = new SectionsFactory())
                            {
                                Sections objSection = objFactory.Creator();
                                if (objSection != null)
                                {
                                    strSTID = objSection.DataItem.intSectionID.ToString();
                                }
                                else
                                {
                                    string strMsg = string.Format("当前网站无栏目ID!插件标识内容为{0}", objPlugin.Xml);
                                    throw new IssueCommon.CustomException(strMsg);
                                }
                            }
                        }
                    }
                    else
                    {
                        // 插件中未定义栏目ID,采用当前栏目ID
                        strSTID = _intDefaultID.ToString();
                    }
                }

                // 文章列表显示的数量
                int intTotalCount = -1;	// -1表示取出所有文章
                string strTotalCount = objPlugin.GetValueByTagName("TotalCount");
                if (strTotalCount != string.Empty)
                {
                    intTotalCount = int.Parse(strTotalCount);
                }

                //strXml = GetCachXml(strSTID, Model.Common.Plugin.PluginType.ArticleList, intTotalCount);
                // 有缓存的Xml,返回缓存数据
                if (strXml != string.Empty)
                {
                    return strXml;
                }

                using (SectionsFactory objFactory = new SectionsFactory())
                {
                    Sections objSection = null;
                    if (strSTID.IndexOf(',') == -1 && strContainChildSection == "1")
                    {
                        string strSTid = strSTID;
                        GetSectionFromParentId(ref strSTid, Convert.ToInt32(strSTid));
                        objSection = objFactory.CreatorBySql(string.Format("0=0 and intSectionID in({0})", strSTid));
                        if (objSection != null)
                        {
                            objSection.SessionUser = sessionUser;
                        }
                    }
                    else
                    {
                        objSection = objFactory.CreatorBySql(string.Format("0=0 and intSectionID in({0})", strSTID.Replace('M', ',')));
                        if (objSection != null)
                        {
                            objSection.SessionUser = sessionUser;
                        }
                    }

                    if (objSection == null)
                    {
                        if (bolIsGlobalStatus == true)
                        {
                            objSection = objFactory.Creator();
                            objSection.SessionUser = sessionUser;
                        }
                        else
                        {
                            //string strMsg = string.Format("处理文章列表插件时未找到栏目，ID={0}", strSTID);
                            //throw new IssueCommon.CustomException(strMsg);
                            return Common.Xml.XmlHelper.GetNewXMLDoc();
                        }
                    }

                    // 栏目停用，不发布
                    if (objSection.DataItem.intState == (int)Common.Section.STState.Canceled)
                    {
                        strXml = string.Empty;	// 需要返回空字串,以替换模板中的相应内容
                    }
                    else if (objSection.DataItem.intDisplay == (int)Common.Section.STDisplay.No) // 栏目不显示，不发布
                    {
                        strXml = string.Empty;
                    }
                    else
                    {
                        //效验Xslt
                        string strMsg = ValidationXslt.ValidationXsltFormat(objPlugin.Xslt, objSection.DataItem.chvSTCName);
                        if (strMsg != string.Empty)
                        {
                            throw new IssueCommon.CustomException(strMsg + "\\n错误详细信息：栏目ID：" + strSTID);
                        }
                        strXml = objSection.GetSinglePageArticleXML(intTotalCount, strSqlArticleStatue.ToString(), bolIsGlobalStatus, bolFilterSame, bolShowInIndex, sessionUser, objSection.Count, bolFilterCurrentArticle, intArtSecID);

                        // 将Xml缓存
                        //XmlCach objXmlCach = new XmlCach(intSTID, Model.Common.Plugin.PluginType.ArticleList, intTotalCount, strXml);
                        //m_aryXmlCach.Add(objXmlCach);
                    }
                }
            }
            else
            {
                strXml = Common.Xml.XmlHelper.GetNewXMLDoc();
            }

            return string.IsNullOrEmpty(strXml)?Common.Xml.XmlHelper.GetNewXMLDoc(): strXml;
        }

        /// <summary>
        /// 处理兄弟栏目列表插件
        /// </summary>
        /// <param name="objPlugin"></param>
        /// <returns></returns>
        public static string ReplaceBrotherSectionList(Plugin objPlugin, int _intDefaultID, SessionUser objSessionUser)
        {
            string strXml = string.Empty;
            string strSTID = objPlugin.GetValueByTagName("id");
            string isChild = objPlugin.GetValueByTagName("child");//0否1是
            string strRecursionChildren = objPlugin.GetValueByTagName("RecursionChildren");
            string strShowInIndex = objPlugin.GetValueByTagName("ShowInIndex");
            string strGoToParen = objPlugin.GetValueByTagName("GoToParen");	// 转到特定的上几级栏目
            int intGoToParent = -1;
            bool bolRecursionChildren = false;
            bool bolShowInIndex = false;
            int intSTID = 0;
            bool bolDisabled = false;
            //是否禁用
            string strDisabled = objPlugin.GetValueByTagName("disabled");
            if (strDisabled != string.Empty)
            {
                if (strDisabled == "1")
                {
                    bolDisabled = true;
                }
            }

            if (bolDisabled == false)
            {
                if (isChild == string.Empty)
                {
                    isChild = "0";
                }
                else
                {
                    if (!ValidateCommon.ParamAuth.IsNumber(isChild))
                    {
                        isChild = "0";
                    }
                    else
                    {
                        if (isChild != "1")
                        {
                            isChild = "0";
                        }
                    }
                }

                if (strGoToParen != string.Empty)
                {
                    if (ValidateCommon.ParamAuth.IsNumber(strGoToParen))
                    {
                        if (Convert.ToInt32(strGoToParen) > 0)
                        {
                            intGoToParent = Convert.ToInt32(strGoToParen);
                        }
                    }
                }

                if (strShowInIndex != string.Empty)
                {
                    if (strShowInIndex == "1")
                    {
                        bolShowInIndex = true;
                    }
                }

                if (strRecursionChildren != string.Empty)
                {
                    if (strRecursionChildren == "1")
                    {
                        bolRecursionChildren = true;
                    }
                }

                if (strSTID == string.Empty)
                {
                    if (_intDefaultID == -1)
                    {
                        string strMsg = string.Format("插件中无栏目ID!插件标识内容为{0}", objPlugin.Xml);
                        throw new IssueCommon.CustomException(strMsg);
                    }
                    // 插件中未定义栏目ID,采用当前栏目ID
                    intSTID = _intDefaultID;
                }
                else
                {
                    intSTID = int.Parse(strSTID);
                }
                if (intGoToParent > 0)
                {
                    int intCurrentSectionID = intSTID;
                    BusinessLogic.BusinessRules.Sections.GetParentSectionID(intCurrentSectionID, intGoToParent, ref intSTID);
                }
                //strXml = GetCachXml(intSTID, Model.Common.Plugin.PluginType.BrotherSectionList, 0);
                //// 有缓存的Xml,返回缓存数据
                //if (strXml != string.Empty)
                //{
                //    return strXml;
                //}

                using (SectionsFactory objFactory = new SectionsFactory())
                {
                    Sections objSection = objFactory.CreatorByBrotherSectionID(intSTID);
                    if (objSection == null)
                    {
                        string strMsg = string.Format("未找到栏目，ID={0}", intSTID);
                        throw new IssueCommon.CustomException(strMsg);
                    }
                    else
                    {
                        objSection.SessionUser = objSessionUser;
                        if (int.Parse(isChild) == 0)
                            strXml = objSection.GetBrotherSectionListXml(intSTID, true, bolShowInIndex, bolRecursionChildren);

                        if (int.Parse(isChild) == 1)
                            strXml = objSection.GetBrotherSectionListXml(intSTID, false, bolShowInIndex, bolRecursionChildren);
                    }
                    // 将Xml缓存
                    //XmlCach objXmlCach = new XmlCach(intSTID, Model.Common.Plugin.PluginType.BrotherSectionList, 0, strXml);
                    //m_aryXmlCach.Add(objXmlCach);
                }
            }
            else
            {
                strXml = Common.Xml.XmlHelper.GetNewXMLDoc();
            }
            return strXml;
        }

        /// <summary>
        /// 递归栏目列表插件
        /// </summary>
        /// <param name="objPlugin"></param>
        /// <returns></returns>
        public static string ReplaceSectionListRecursion(Plugin objPlugin, int _intDefaultID, SessionUser objSessionUser)
        {
            string strXml = string.Empty;
            string strSTID = objPlugin.GetValueByTagName("id");
            string strContainArticle = objPlugin.GetValueByTagName("ContainArticle");
            string strContainCurrent = objPlugin.GetValueByTagName("ContainCurrent");
            bool bolContainCurrent = false;
            bool bolContainArticle = false;
            bool bolDisabled = false;
            //是否禁用
            string strDisabled = objPlugin.GetValueByTagName("disabled");
            if (strDisabled != string.Empty)
            {
                if (strDisabled == "1")
                {
                    bolDisabled = true;
                }
            }

            if (bolDisabled == false)
            {
                if (strContainCurrent != string.Empty)
                {
                    if (strContainCurrent == "1")
                    {
                        bolContainCurrent = true;
                    }
                }
                if (strContainArticle != string.Empty)
                {
                    if (strContainArticle == "1")
                    {
                        bolContainArticle = true;
                    }
                }
                int intSTID = 0;
                if (strSTID == string.Empty)
                {
                    if (_intDefaultID == -1)
                    {
                        string strMsg = string.Format("插件中无栏目ID!插件标识内容为{0}", objPlugin.Xml);
                        throw new IssueCommon.CustomException(strMsg);
                    }
                    // 插件中未定义栏目ID,采用当前栏目ID
                    intSTID = _intDefaultID;
                }
                else
                {
                    intSTID = int.Parse(strSTID);
                }

                //strXml = GetCachXml(intSTID, Model.Common.Plugin.PluginType.BrotherSectionList, 0);
                //// 有缓存的Xml,返回缓存数据
                //if (strXml != string.Empty)
                //{
                //    return strXml;
                //}

                using (SectionsFactory objFactory = new SectionsFactory())
                {
                    Sections objSection = objFactory.CreatorByBrotherSectionID(intSTID);
                    if (objSection == null)
                    {
                        string strMsg = string.Format("未找到栏目，ID={0}", intSTID);
                        throw new IssueCommon.CustomException(strMsg);
                    }
                    else
                    {
                        if (bolContainCurrent == false)
                        {
                            strXml = objSection.GetSectionListRecursionXml(intSTID, false, !bolContainCurrent, bolContainArticle, objSessionUser);
                        }
                        else
                        {
                            //string strTemp = objSection.GetSectionListRecursionXml(intSTID, false, !bolContainCurrent, bolContainArticle, objSessionUser);
                            //strXml = objSection.ReplaceSectionPlugin();
                            strXml = "";
                        }
                    }
                    // 将Xml缓存
                    //XmlCach objXmlCach = new XmlCach(intSTID, Model.Common.Plugin.PluginType.BrotherSectionList, 0, strXml);
                    //m_aryXmlCach.Add(objXmlCach);
                }
            }
            else
            {
                strXml = Common.Xml.XmlHelper.GetNewXMLDoc();
            }
            return strXml;
        }
        /// <summary>
        /// 处理栏目插件
        /// </summary>
        /// <param name="objPlugin"></param>
        /// <returns></returns>
        public static string ReplaceSectionPlugin(Plugin objPlugin, int _intDefaultID, SessionUser objSessionUser)
        {
            string strXml = string.Empty;
            bool bolShowInIndex = false;
            string strSTID = objPlugin.GetValueByTagName("id");
            string strShowInIndex = objPlugin.GetValueByTagName("ShowInIndex");

            //是否子栏目
            bool bolContainChildrenSection = false;
            string strContainChildrenSection = objPlugin.GetValueByTagName("ContainChildrenSection");

            //是否包含下属文章
            bool bolContainArticle = false;
            string strContainArticle = objPlugin.GetValueByTagName("ContainArticle");

            //是否禁用
            bool bolDisabled = false;
            string strDisabled = objPlugin.GetValueByTagName("disabled");
            if (strDisabled != string.Empty)
            {
                if (strDisabled == "1")
                {
                    bolDisabled = true;
                }
            }

            if (bolDisabled == false)
            {
                if (strContainArticle != string.Empty)
                {
                    if (strContainArticle == "1")
                    {
                        bolContainArticle = true;
                    }
                }
                if (strContainChildrenSection != string.Empty)
                {
                    if (strContainChildrenSection == "1")
                    {
                        bolContainChildrenSection = true;
                    }
                }
                if (strShowInIndex != string.Empty)
                {
                    if (strShowInIndex == "1")
                    {
                        bolShowInIndex = true;
                    }
                }
                int intSTID = 0;
                if (strSTID == string.Empty)
                {
                    if (_intDefaultID == -1)
                    {
                        string strMsg = string.Format("插件中无栏目ID!插件标识内容为{0}", objPlugin.Xml);
                        throw new IssueCommon.CustomException(strMsg);
                    }
                    // 插件中未定义栏目ID,采用当前栏目ID
                    intSTID = _intDefaultID;
                }
                else
                {
                    intSTID = int.Parse(strSTID);
                }
                // 栏目列表显示的数量
                int intTotalCount = -1;	// -1表示取出所有栏目
                string strTotalCount = objPlugin.GetValueByTagName("TotalCount");
                if (strTotalCount != string.Empty)
                {
                    intTotalCount = int.Parse(strTotalCount);
                }
                ////			strXml = GetCachXml(intSTID, Model.Common.Plugin.PluginType.Section, 0) ;
                ////strXml = GetCachXml(intSTID, Model.Common.Plugin.PluginType.Section, intTotalCount);
                //if (SetCachecs.SetCache.GetCache(intSTID.ToString() + (bolShowInIndex == false ? "_0" : "_1")) != null)
                //    strXml = SetCachecs.SetCache.GetCache(intSTID.ToString() + (bolShowInIndex == false ? "_0" : "_1")).ToString();
                //// 有缓存的Xml,返回缓存数据
                //if (strXml != string.Empty)
                //{
                //    return strXml;
                //}

                using (SectionsFactory objFactory = new SectionsFactory())
                {
                    Sections objSection = objFactory.Creator(intSTID);
                    if (objSection != null)
                    {
                        objSection.SessionUser = objSessionUser;
                        if (objSection == null)
                        {
                            string strMsg = string.Format("未找到栏目，ID={0}", intSTID);
                            throw new IssueCommon.CustomException(strMsg);
                        }
                        // 栏目停用，不发布
                        if (objSection.DataItem.intState == (int)Utility.STState.NoUse)
                        {
                            strXml = string.Empty;	// 需要返回空字串,以替换模板中的相应内容
                        }
                        else if (objSection.DataItem.intDisplay == (int)Common.Section.STDisplay.No) // 栏目不显示，不发布
                        {
                            strXml = string.Empty;
                        }
                        else
                        {
                            strXml = objSection.GetSectionXml(intTotalCount, bolShowInIndex, bolContainChildrenSection, bolContainArticle);
                            // 将Xml缓存
                            SetCachecs.SetCache.Insert(intSTID.ToString() + (bolShowInIndex == false ? "_0" : "_1"), strXml);
                        }
                    }
                    else
                    {
                        strXml = Common.Xml.XmlHelper.GetNewXMLDoc();
                    }
                }
            }
            else
            {
                strXml = Common.Xml.XmlHelper.GetNewXMLDoc();
            }

            return strXml;
        }

        /// <summary>
        /// 处理父栏目字段插件
        /// </summary>
        /// <param name="objPlugin"></param>
        /// <returns></returns>
        public static string ReplaceParentSection(Plugin objPlugin, int _intDefaultID, SessionUser objSessionUser)
        {
            string strXml = string.Empty;
            string strSTID = objPlugin.GetValueByTagName("id");
            int intSTID = 0;
            bool bolDisabled = false;
            //是否禁用
            string strDisabled = objPlugin.GetValueByTagName("disabled");
            if (strDisabled != string.Empty)
            {
                if (strDisabled == "1")
                {
                    bolDisabled = true;
                }
            }

            if (bolDisabled == false)
            {
                if (strSTID == string.Empty)
                {
                    if (_intDefaultID == -1)
                    {
                        string strMsg = string.Format("插件中无栏目ID!插件标识内容为{0}", objPlugin.Xml);
                        throw new Model.Common.CustomException(strMsg);
                    }
                    // 插件中未定义栏目ID,采用当前栏目ID
                    intSTID = _intDefaultID;
                }
                else
                {
                    intSTID = int.Parse(strSTID);
                }

                //strXml = GetCachXml(intSTID, Model.Common.Plugin.PluginType.ParentSection, 0);
                // 有缓存的Xml,返回缓存数据
                //if (strXml != string.Empty)
                //{
                //    return strXml;
                //}

                using (SectionsFactory objFactory = new SectionsFactory())
                {
                    Sections objSection = objFactory.CreatorByParentSectionID(intSTID);
                    if (objSection == null)
                    {
                        strXml = Common.Xml.XmlHelper.GetNewXMLDoc();
                        //string strMsg = string.Format("未找到栏目ID={0}的父栏目", intSTID);
                        //throw new Model.Common.CustomException(strMsg);
                    }
                    else
                    {
                        objSection.SessionUser = objSessionUser;
                        strXml = objSection.GetParentSectionXml();
                    }
                    // 将Xml缓存
                    //XmlCach objXmlCach = new XmlCach(intSTID, Model.Common.Plugin.PluginType.ParentSection, 0, strXml);
                    //m_aryXmlCach.Add(objXmlCach);
                }
            }
            else
            {
                strXml = Common.Xml.XmlHelper.GetNewXMLDoc();
            }
            return strXml;
        }

        /// <summary>
        /// 处理文章列表插件,获取特定栏目子栏目文章列表
        /// </summary>
        /// <param name="objPlugin"></param>
        /// <returns></returns>
        public static string ReplaceChildSectionArticleListPlugin(Plugin objPlugin, int _intDefaultID, SessionUser sessionUser)
        {
            // 文章所在栏目ID
            string strXml = string.Empty;
            string strSTID = objPlugin.GetValueByTagName("id");
            int intSTID = 0;
            StringBuilder strSqlArticleStatue = new StringBuilder();
            bool bolIsGlobalStatus = false;
            bool bolFilterSame = false;
            bool bolShowInIndex = false;
            bool bolDisabled = false;
            //置顶
            string strTop = objPlugin.GetValueByTagName("top");
            //推荐
            string strRec = objPlugin.GetValueByTagName("rec");
            //审核
            string strVerify = objPlugin.GetValueByTagName("verify");
            //滚动新闻
            string strScroll = objPlugin.GetValueByTagName("scroll");
            //显示在首页
            string strShowInIndex = objPlugin.GetValueByTagName("ShowInIndex");
            //过滤重复
            string strContainFilterSame = objPlugin.GetValueByTagName("FilterSame");
            string strDisabled = objPlugin.GetValueByTagName("disabled");
            if (strDisabled != string.Empty)
            {
                if (strDisabled == "1")
                {
                    bolDisabled = true;
                }
            }
            if (bolDisabled == false)
            {
                if (strContainFilterSame != string.Empty)
                {
                    if (strContainFilterSame == "1")
                    {
                        bolFilterSame = true;
                    }
                }
                if (strShowInIndex != string.Empty)
                {
                    if (strShowInIndex == "1")
                    {
                        bolShowInIndex = true;
                    }
                }
                if (strTop != string.Empty)
                {
                    if (strTop == "1" && strSTID == string.Empty)
                    {
                        //全局置顶
                        strSqlArticleStatue.Append(string.Format(" and intGlobalTop ={0}", strTop));
                        bolIsGlobalStatus = true;
                    }
                    else if (strTop == "1" && strSTID != string.Empty)
                    {
                        //板块置顶
                        strSqlArticleStatue.Append(string.Format(" and intSectionTop ={0}", strTop));
                    }
                }
                else if (strRec != string.Empty)
                {
                    if (strRec == "1" && strSTID == string.Empty)
                    {
                        //全局推荐
                        strSqlArticleStatue.Append(string.Format(" and intGlobalRec ={0}", strRec));
                        bolIsGlobalStatus = true;
                    }
                    else if (strRec == "1" && strSTID != string.Empty)
                    {
                        //板块推荐
                        strSqlArticleStatue.Append(string.Format(" and intSectionRec ={0}", strRec));
                    }
                }
                else if (strVerify != string.Empty)
                {
                    if (strVerify == "1" && strSTID == string.Empty)
                    {
                        //全局审核
                        strSqlArticleStatue.Append(string.Format(" and intVerify ={0}", strVerify));
                        bolIsGlobalStatus = true;
                    }
                    else if (strVerify == "1" && strSTID != string.Empty)
                    {
                        //板块审核
                        strSqlArticleStatue.Append(string.Format(" and intVerify ={0}", strVerify));
                    }
                }
                else if (strScroll != string.Empty)
                {
                    if (strScroll == "1" && strSTID == string.Empty)
                    {
                        //全局滚动
                        strSqlArticleStatue.Append(string.Format(" and intScroll ={0}", strScroll));
                        bolIsGlobalStatus = true;
                    }
                    else if (strScroll == "1" && strSTID != string.Empty)
                    {
                        //板块滚动
                        strSqlArticleStatue.Append(string.Format(" and intScroll ={0}", strScroll));
                    }
                }
                if (strSTID == string.Empty)
                {
                    if (_intDefaultID == -1)
                    {
                        if (bolIsGlobalStatus == false)
                        {
                            string strMsg = string.Format("插件中无栏目ID!插件标识内容为{0}", objPlugin.Xml);
                            throw new IssueCommon.CustomException(strMsg);
                        }
                        else
                        {
                            using (SectionsFactory objFactory = new SectionsFactory())
                            {
                                Sections objSection = objFactory.Creator();
                                if (objSection != null)
                                {
                                    strSTID = objSection.DataItem.intSectionID.ToString();
                                }
                                else
                                {
                                    string strMsg = string.Format("当前网站无栏目ID!插件标识内容为{0}", objPlugin.Xml);
                                    throw new IssueCommon.CustomException(strMsg);
                                }
                            }
                        }
                    }
                    else
                    {
                        // 插件中未定义栏目ID,采用当前栏目ID
                        strSTID = _intDefaultID.ToString();
                    }
                }

                // 文章列表显示的数量
                int intTotalCount = -1;	// -1表示取出所有文章
                string strTotalCount = objPlugin.GetValueByTagName("TotalCount");
                if (strTotalCount != string.Empty)
                {
                    intTotalCount = int.Parse(strTotalCount);
                }

                //strXml = GetCachXml(intSTID, Model.Common.Plugin.PluginType.ChildSectionArticleList, intTotalCount);
                //// 有缓存的Xml,返回缓存数据
                //if (strXml != string.Empty)
                //{
                //    return strXml;
                //}

                using (SectionsFactory objFactory = new SectionsFactory())
                {
                    Sections objSection = objFactory.CreatorByChildSectionID(intSTID);
                    if (objSection == null)
                    {
                        //string strMsg = string.Format("处理文章列表插件时未找到栏目，ID={0}", intSTID);
                        //throw new CommonDll.CustomException(strMsg);
                        strXml = string.Empty;
                    }
                    // 栏目停用，不发布
                    //if (objSection.DataItem.intState == (int)Model.Common.Section.STState.Canceled)
                    //{
                    //    strXml = string.Empty;	// 需要返回空字串,以替换模板中的相应内容
                    //}
                    else if (objSection.DataItem.intDisplay == (int)Common.Section.STDisplay.No) // 栏目不显示，不发布
                    {
                        strXml = string.Empty;
                    }
                    else
                    {
                        //效验
                        string strMsg = ValidationXslt.ValidationXsltFormat(objPlugin.Xslt, objSection.DataItem.chvSTCName);
                        if (strMsg != string.Empty)
                            throw new IssueCommon.CustomException(strMsg + "\\n错误详细信息：栏目ID：" + strSTID);

                        strXml = objSection.GetSinglePageArticleXML(intTotalCount, strSqlArticleStatue.ToString(), bolIsGlobalStatus, bolFilterSame, false, sessionUser, objSection.Count,false,-1);

                        // 将Xml缓存
                        //XmlCach objXmlCach = new XmlCach(intSTID, Model.Common.Plugin.PluginType.ChildSectionArticleList, intTotalCount, strXml);
                        //m_aryXmlCach.Add(objXmlCach);
                    }
                }
            }
            else
            {
                strXml = Common.Xml.XmlHelper.GetNewXMLDoc();
            }

            return strXml;
        }

        /// <summary>
        /// 根据父ID获取子栏目
        /// </summary>
        private static void GetSectionFromParentId(ref string strSTIDlist, int intParentId)
        {
            try
            {
                using (SectionsFactory objFactory = new SectionsFactory())
                {
                    BusinessLogic.BusinessRules.Sections objsection = objFactory.CreatorBySql("intParentID =" + intParentId.ToString());
                    if (objsection != null)
                    {
                        BusinessLogic.BusinessRules.Sections objsectionTemp;
                        for (int i = 0; i < objsection.Count; i++)
                        {
                            strSTIDlist = strSTIDlist + "," + objsection.DataItem.intSectionID;
                            objsectionTemp = objFactory.CreatorBySql("intParentID =" + objsection.DataItem.intSectionID.ToString());
                            if (objsectionTemp != null)
                            {
                                for (int j = 0; j < objsectionTemp.Count; j++)
                                {
                                    strSTIDlist = strSTIDlist + "," + objsectionTemp.DataItem.intSectionID;
                                    GetSectionFromParentId(ref strSTIDlist, objsectionTemp.DataItem.intSectionID);
                                    objsectionTemp.SelectRow(j + 1);
                                }
                            }
                            objsection.SelectRow(i + 1);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("获取子栏目ID是发生异常：" + ex.Message.Replace("\r\n", ""));
            }
        }
    }
}